package com.jinyu.jyly.ui.mine.setting.changemobile;

import android.app.Activity;

import com.jinyu.jyly.base.BasePresenter;
import com.jinyu.jyly.bean.AllInfoBean;
import com.jinyu.jyly.net.DataManager;

import rx.Subscription;
import rx.functions.Action1;

public class ChangeMobilePresenter extends BasePresenter<ChangeMobileContract.View> implements ChangeMobileContract.Presenter {

    public ChangeMobilePresenter(Activity activity, ChangeMobileContract.View view) {
        super(activity, view);
    }

    /**
     * 修改手机号
     */
   @Override
    public void changeMobile(String param) {
        Subscription subscribe = DataManager.getInstance().changeMobile(param)
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean InfoData) {
                        if (InfoData != null) {
                            mView.onChangeMobile(InfoData);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        throwable.printStackTrace();
                        mView.onFailer(throwable);
                    }
                });
        addSubscribe(subscribe);
    }

    /**
     * 登录后发送短信
     * @param
     */
    @Override
    public void siteMakeSms() {
        Subscription subscribe = DataManager.getInstance().siteMakeSms()
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean InfoData) {
                        if (InfoData != null) {
                            mView.onSiteMakeSms(InfoData);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        throwable.printStackTrace();
                        mView.onFailer(throwable);
                    }
                });
        addSubscribe(subscribe);
    }

    /**
     * 修改联系人手机号
     * @param param
     */
    @Override
    public void changeContractMobile(String param) {
        Subscription subscribe = DataManager.getInstance().changeContractMobile(param)
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean InfoData) {
                        if (InfoData != null) {
                            mView.onChangeContractMobile(InfoData);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        throwable.printStackTrace();
                        mView.onFailer(throwable);
                    }
                });
        addSubscribe(subscribe);
    }


}
